using System;

namespace Randomize.Core.Generators
{
    public abstract class Generator<T> : IGenerator<T>
    {
        public T[] Pool { get; set; }

        public Random RandomInstance { get; set; }

        protected Generator(Random random)
        {
            this.RandomInstance = random;
        }

        protected virtual T GenerateFromPool()
        {
            if (Pool != null)
            {
                var randomIndex = RandomInstance.Next(Pool.Length);
                return Pool[randomIndex];
            }

            return default(T);
        }

        protected abstract T GenerateRandomValue();

        public virtual T Generate()
        {
            if (Pool != null)
            {
                return this.GenerateFromPool();
            }

            return this.GenerateRandomValue();
        }
    }
}